import {DICTIONARY_FIND_All} from '@CRM/api/sysDictionary.js'

export const dictionary = {
  namespaced: true,
  state: {
    dictionaryMap: null,
  },
  mutations: {
    setDictionaryMap(state, dictionaryMap) {
      state.dictionaryMap = { ...state.dictionaryMap, ...dictionaryMap }
    }
  },
  actions: {
    // 从后台获取全部
    async getDictionary({ commit, state }, types) {
      var res = await DICTIONARY_FIND_All({ dictType: types, isSystem: null })
      if (res.code === 0) {
        state.dictionaryMap = res.data || {}
        commit('setDictionaryMap', res.data)
        return state.dictionaryMap
      }
    },
    async getJsonData({ commit, state }) {
      console.log(2212)
    }
  },
  getters: {
    getDictionary(state) {
      return state.dictionaryMap || {}
    }
  }
}
